package org.pada.domain.util;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.GenericTypeResolver;

import java.lang.reflect.Type;

/**
 * @author shen.peng
 * @since 2024/10/31
 */
@Slf4j
@Configuration
public class JsonUtil extends org.pada.client.util.JsonUtil {
    @Bean
    public ObjectMapper getMapper() {
        return MAPPER;
    }

    public static JavaType getJavaType(Type type, Class<?> clazz) {
        TypeFactory typeFactory = MAPPER.getTypeFactory();
        return typeFactory.constructType(GenericTypeResolver.resolveType(type, clazz));
    }
}
